﻿using System.Collections.Generic;

namespace BitButterCORE.Component
{
	public abstract class BaseComponent { }

	public abstract class BaseComponent<T> : BaseComponent
	{
		public virtual T Value => value;
		protected T value;

		protected List<T> ChangeCache => changeCache ?? (changeCache = new List<T>());
		List<T> changeCache;

		public virtual bool HasChanges => ChangeCache.Count > 0;

		public virtual void Commit(T change)
		{
			ChangeCache.Add(change);
		}

		public abstract void Merge();

		public virtual void ForceSet(T value)
		{
			this.value = value;
		}

		public virtual byte[] Serialize()
		{
			return null;
		}

		public virtual void Deserialize(byte[] componentPayload)
		{
		}
	}
}
